<template>
  <div>
    <TopFilter
      :list="topFilterList"
      :cols="4"
      @filterChange="changeHandle"
      @onCollapse="collapseHandle"
    ></TopFilter>

    <FilterTable
      ref="table"
      :columns="columns"
      :fetchapi="fetchApi"
      :params="fetchParams"
      :datakey="'records'"
      :onColumnsChange="columns => this.columns = columns"
      height="auto"
    >
      <template slot="controls" slot-scope="props">
        <multiuse-button v-if="dataType !== '10461001'" size="small" type="primary" :click="AddCars" :auth-list="auths" auth-mark="/api/basedata/vehicleProduct/car/insertCarPrice"
          >新增</multiuse-button
        >
        <multiuse-button size="small" type="primary" :click="downloadTemplate" :auth-list="auths" auth-mark="/api/7">下载模板</multiuse-button>
        <multiuse-button size="small" type="primary" :click="importPrice" :auth-list="auths" auth-mark="/api/8">导入</multiuse-button>
        <!-- <el-button size="small" type="primary" :loading="exportLoading" @click="requestExportData">导出</el-button> -->
        <multiuse-button size="small" type="primary" :loading="exportLoading" :click="requestExportData" :auth-list="auths" auth-mark="/api/basedata/vehicleProduct/productInfo/export/excel"
          >导出</multiuse-button
        >
       </template>
    </FilterTable>
    <BaseDialog
      :visible.sync="visible"
      :title="dialogTitle"
      destroyOnClose
      width="80%"
      :containerStyle="{height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px'}"
    >
      <dataCarsPanel :type="handleType" :productId="productId" :rowData="formData" @close="closeHandler" />
    </BaseDialog>

    <BaseDialog
      :visible.sync="visibleImport"
      :title="'导入价格'"
      destroyOnClose
      :containerStyle="{height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px'}"
    >
      <!-- <importPricePanel @close="closeImportHandler" /> -->
      <importFile
        title="导入"
        actionUrl="/api/basedata/vehicleProduct/car/importCarPrice"
        @close="closeImportHandler"
        />
    </BaseDialog>

    <BaseDialog
      :visible.sync="visibleAddCars"
      :title="'新增'"
      destroyOnClose
      :containerStyle="{height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px'}"
    >
      <masterCarsModal :type="handleType" :rowData="formData" @close="closeAddCarsHandler" />
    </BaseDialog>
  </div>
</template>

<script>
import {
  getCar,
  getCarOEM,
  getBrandList,
  getSeriesList,
  getModelList,
  getPackageList,
  getOptionListDictOEM,
  getWcolorList,
  getIcolorList,
  addCar,
  updateCar,
  getCarExport,
  importCar,
  getExcelList
 } from '@/api/common/cars/masterDataCars';
import { dictionary } from '@/utils/dictMixin';
import dataCarsPanel from './dataCarsPanel';
import importPricePanel from './importPricePanel';
import masterCarsModal from './masterCarsModal';
import { exportExcelFile } from '@/utils/index';
import { authority } from '@/utils/authMixin';
import Cookies from 'js-cookie';
export default {
  name: 'Masterdatacars',
  mixins: [dictionary,authority],
  components: {
    dataCarsPanel,
    importPricePanel,
    masterCarsModal
  },
  data() {
    return {
      topFilterList: Cookies.get('dataType') !== '10461001'?this.createTopFilters():this.createTopFilters2(),
      productId:"",
      fetchParams: {
        pageNum: 1,
        productId: '',
        productCode: '',
        productName: '',
        productStatus: '',
        productType: '',
        brandName: '',
        seriesName: '',
        modelName: '',
        packageName: '',
        brandId: '',
        seriesId: '',
        modelId: '',
        packageId: '',
        interiorColor: '',
        color: '',
        enterDate: '',
        exeuntDate: '',
        oemDirectivePrice: '',
        vehiclePrice: '',
        dataSources: '',
        vehicleSources: '',
        isValid: '',
        remark: ''
      },
      visible: false,
      visibleImport: false,
      dialogTitle: '',
      fetchApi: Cookies.get('dataType') !== '10461001'?getCarOEM:getCar,
      columns: Cookies.get('dataType') !== '10461001'?this.createTableColumns():this.createTableColumns2(),
      handleType: '',
      formData: {},
      conf:{ add: '新增', edit: '编辑', show: '显示' },
      exportLoading: false,
      dataType: Cookies.get('dataType'),// 判断是否为厂端
      visibleAddCars: false,
    };
  },
  filters: {
    date(time) {
      let newTime = Number(time)
      var d = new Date(newTime)
      var year = d.getFullYear()
      var month = d.getMonth() + 1
      var day = d.getDate() < 10 ? '0' + d.getDate() : '' + d.getDate()
      var hour = d.getHours() < 10 ? '0' + d.getHours() : '' + d.getHours()
      var minutes =
        d.getMinutes() < 10 ? '0' + d.getMinutes() : '' + d.getMinutes()
      var seconds =
        d.getSeconds() < 10 ? '0' + d.getSeconds() : '' + d.getSeconds()
      return (
        year +
        '-' +
        month +
        '-' +
        day +
        ' ' +
        hour +
        ':' +
        minutes +
        ':' +
        seconds
      )
    }
  },
  methods: {
    createTopFilters() {
      return [
        {
          type: 'INPUT',
          label: '产品代码',
          fieldName: 'productCode',
          placeholder: '请输入'
        },
        {
          type: 'INPUT',
          label: '产品名称',
          fieldName: 'productName',
          placeholder: '请输入'
        },
        /* {
          type: 'INPUT',
          label: '颜色名称',
          fieldName: 'colorName',
          placeholder: '请输入'
        }, */

        {
          type: 'SELECT',
          label: '品牌',
          fieldName: 'brandId',
          placeholder: '请选择',
          itemList: [],
          change: val => {
            this.changeBrandSelect(val);
          }
        },
        {
          type: 'SELECT',
          label: '车系',
          fieldName: 'seriesId',
          placeholder: '请选择',
          itemList: [],
          change: val => {
            this.changeSeriesSelect(val);
          }
        },
        {
          type: 'SELECT',
          label: '车型',
          fieldName: 'modelId',
          placeholder: '请选择',
          itemList: [],
          change: val => {
            this.changeModelSelect(val);
          }
        },
        {
          type: 'SELECT',
          label: '配置',
          fieldName: 'packageId',
          placeholder: '请选择',
          itemList: []
        },
        {
          type: 'SELECT',
          // type: 'INPUT',
          label: '外饰色',
          // fieldName: 'colorStr',
          fieldName: 'colorId',
          placeholder: '请选择',
          itemList: []
        },
        {
          type: 'SELECT',
          // type: 'INPUT',
          label: '内饰色',
          fieldName: 'trimColorId',
          // fieldName: 'interiorColor',
          placeholder: '请选择',
          itemList: []
        },

        {
          type: 'SELECT',
          label: '产品状态',
          fieldName: 'productStatus',
          placeholder: '请选择',
          itemList: this.createDictList('1408')
        },
        /* {
          type: 'SELECT',
          label: '数据来源',
          fieldName: 'dataSources',
          placeholder: '请选择',
          itemList: this.createDictList('1045')
        }, */
        {
          type: 'SELECT',
          label: '是否有效',
          fieldName: 'isValid',
          placeholder: '请选择',
          itemList: this.createDictList('1004')
        }
      ];
    },
    createTopFilters2() {
      return [
        {
          type: 'INPUT',
          label: '产品代码',
          fieldName: 'productCode',
          placeholder: '请输入'
        },
        {
          type: 'INPUT',
          label: '产品名称',
          fieldName: 'productName',
          placeholder: '请输入'
        },
        /* {
          type: 'INPUT',
          label: '颜色名称',
          fieldName: 'colorName',
          placeholder: '请输入'
        }, */

        {
          type: 'SELECT',
          label: '品牌',
          fieldName: 'brandId',
          placeholder: '请选择',
          itemList: [],
          change: val => {
            this.changeBrandSelect(val);
          }
        },
        {
          type: 'SELECT',
          label: '车系',
          fieldName: 'seriesId',
          placeholder: '请选择',
          itemList: [],
          change: val => {
            this.changeSeriesSelect(val);
          }
        },
        {
          type: 'SELECT',
          label: '车型',
          fieldName: 'modelId',
          placeholder: '请选择',
          itemList: [],
          change: val => {
            this.changeModelSelect(val);
          }
        },
        {
          type: 'SELECT',
          label: '配置',
          fieldName: 'packageId',
          placeholder: '请选择',
          itemList: [],
          change: val => {
            this.changePackageSelect(val);
          }
        },
        {
          type: 'SELECT',
          label: '选装',
          fieldName: 'optionId',
          placeholder: '请选择',
          itemList: []
        },
        {
          // type: 'SELECT',
          type: 'INPUT',
          label: '外饰色',
          fieldName: 'colorStr',
          // fieldName: 'colorId',
          placeholder: '请选择',
          // itemList: []
        },
        {
          // type: 'SELECT',
          type: 'INPUT',
          label: '内饰色',
          fieldName: 'trimColor',
          // fieldName: 'interiorColor',
          placeholder: '请选择',
          // itemList: []
        },

        {
          type: 'SELECT',
          label: '产品状态',
          fieldName: 'productStatus',
          placeholder: '请选择',
          itemList: this.createDictList('1408')
        },
        /* {
          type: 'SELECT',
          label: '数据来源',
          fieldName: 'dataSources',
          placeholder: '请选择',
          itemList: this.createDictList('1045')
        }, */
        {
          type: 'SELECT',
          label: '是否有效',
          fieldName: 'isValid',
          placeholder: '请选择',
          itemList: this.createDictList('1004')
        }
      ];
    },
    downloadTemplate(){
        this.$confirm('下载模板', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          window.open("/static/tinymce/template/carPriceTemplate.xls");
          this.$message({
            type: 'success',
            message: '下载成功!'
          });
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          });
        });

    },

    importPrice(){
      this.visibleImport = true;
    },
    AddCars(){
      this.handleType = 'add';
      this.visibleAddCars = true;
    },
    editHandleCars(row){
      console.log(row)
      this.handleType = 'edit';
      this.productId = row.productId;
      this.formData = row;
      if (this.dataType !== '10461001') {
        this.visibleAddCars = true;
      } else {
        this.visible =true
      }
    },
    detailHandleCars(row) {
      console.log(row)
      this.handleType = 'show';
      this.formData = row;
      if (this.dataType !== '10461001') {
        this.visibleAddCars = true;
      } else {
        this.visible =true
      }
    },
    createTableColumns() {
      return [
        {
          title: '操作',
          dataIndex: 'column-action',
          width: 100,
          fixed: 'left',
          render: (props, h) => {
            return (
              <div>
                <el-button size="mini" type="text" onClick={() => this.detailHandleCars(props.row)}>
                  明细
                </el-button>
                <multiuse-button size="mini" divider="before" type="text" onClick={() => this.editHandleCars(props.row)} auth-list={this.auths} auth-mark={'/api/basedata/vehicleProduct/car/editCarPrice'}>
                  编辑
                </multiuse-button>
              </div>
            );
          }
        },
        {
          title: '序号',
          dataIndex: 'index',
          width: 80,
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '产品名称',
          dataIndex: 'productName',
          width: 220,
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '产品代码',
          dataIndex: 'productCode',
          width: 130,
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '品牌',
          dataIndex: 'brandName',
          width: 120,
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '车系',
          dataIndex: 'seriesName',
          width: 120,
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '车型',
          dataIndex: 'modelName',
          width: 120,
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '配置',
          dataIndex: 'packageName',
          width: 120,
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '外饰色',
          dataIndex: 'color',
          width: 120,
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '内饰色',
          dataIndex: 'trimColor',
          width: 120,
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '车辆来源',
          dataIndex: 'vehicleSources',
          width: 120,
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList('1901'),
          render: props => {
            return <span>{this.createDictText(props.row.vehicleSources, '1901')}</span>;
          }
        },
        {
          title: '产品状态',
          dataIndex: 'productStatus',
          width: 120,
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList('1408'),
          render: props => {
            return <span>{this.createDictText(props.row.productStatus, '1408')}</span>;
          }
        },
        {
          title: '车厂指导价',
          dataIndex: 'oemDirectivePrice',
          width: 160,
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '采购单价',
          dataIndex: 'purchasePrice',
          width: 120,
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '上市日期',
          dataIndex: 'enterDate',
          sorter: true,
          filter: true,
          align: 'center',
          filterType: 'date-range',
          dateFormat: 'yyyy-MM-dd'
        },
        {
          title: '退市日期',
          dataIndex: 'exeuntDate',
          sorter: true,
          filter: true,
          align: 'center',
          filterType: 'date-range',
          dateFormat: 'yyyy-MM-dd'
        },

        {
          title: '备注',
          dataIndex: 'remark',
          width: 120,
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '是否有效',
          dataIndex: 'isValid',
          width: 120,
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList('1004'),
          render: props => {
            return <span>{this.createDictText(props.row.isValid, '1004')}</span>;
          }
        },
      ];
    },
    createTableColumns2() {
      return [
        {
          title: '操作',
          dataIndex: 'column-action',
          width: 100,
          fixed: 'left',
          render: (props, h) => {
            return (
              <div>
                <el-button size="mini" type="text" onClick={() => this.detailHandle(props.row)}>
                  明细
                </el-button>
                <multiuse-button size="mini" divider="before" type="text" onClick={() => this.editHandle(props.row)} auth-list={this.auths} auth-mark={'/api/basedata/vehicleProduct/car/editCarPrice'}>
                  编辑
                </multiuse-button>
              </div>
            );
          }
        },
        {
          title: '序号',
          dataIndex: 'index',
          width: 80,
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '产品代码',
          dataIndex: 'productCode',
          width: 130,
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '产品名称',
          dataIndex: 'productName',
          width: 220,
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '分类代码',
          dataIndex: 'baseCode',
          width: 220,
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '分类名称',
          dataIndex: 'baseName',
          width: 220,
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '品牌',
          dataIndex: 'brandName',
          width: 120,
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '车系',
          dataIndex: 'seriesName',
          width: 120,
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '车型',
          dataIndex: 'modelName',
          width: 120,
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '配置',
          dataIndex: 'packageName',
          width: 120,
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '选装',
          dataIndex: 'optionName',
          width: 120,
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '外饰色',
          dataIndex: 'color',
          width: 120,
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '内饰色',
          dataIndex: 'trimColor',
          width: 120,
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '车辆来源',
          dataIndex: 'vehicleSources',
          width: 120,
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList('1901'),
          render: props => {
            return <span>{this.createDictText(props.row.vehicleSources, '1901')}</span>;
          }
        },
        {
          title: '产品状态',
          dataIndex: 'productStatus',
          width: 120,
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList('1408'),
          render: props => {
            return <span>{this.createDictText(props.row.productStatus, '1408')}</span>;
          }
        },
        {
          title: '车厂指导价',
          dataIndex: 'oemDirectivePrice',
          width: 160,
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '采购单价',
          dataIndex: 'purchasePrice',
          width: 120,
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '整车加价率',
          dataIndex: 'vehicleMarkupRate',
          width: 160,
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '销售指导价',
          dataIndex: 'vehiclePrice',
          width: 140,
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '销售底价',
          dataIndex: 'salesBasePrice',
          width: 120,
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '储备高限',
          dataIndex: 'maxReserve',
          width: 120,
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '储备低限',
          dataIndex: 'minReserve',
          width: 120,
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        /* {
          title: '产品类别',
          dataIndex: 'productType',
          width: 120,
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList('1407'),
          render: props => {
            return <span>{this.createDictText(props.row.productType, '1407')}</span>;
          }
        }, */
        {
          title: '上市日期',
          dataIndex: 'enterDate',
          width: 120,
          sorter: true,
          filter: true,
          filterType: 'input',
          initialValue: this.date
        },
        {
          title: '退市日期',
          dataIndex: 'exeuntDate',
          width: 120,
          sorter: true,
          filter: true,
          filterType: 'input',
          initialValue: this.date
        },

        {
          title: '备注',
          dataIndex: 'remark',
          width: 120,
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '数据来源',
          dataIndex: 'dataSources',
          width: 120,
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList('1045'),
          render: props => {
            return <span>{this.createDictText(props.row.dataSources, '1045')}</span>;
          }
        },
        {
          title: '是否有效',
          dataIndex: 'isValid',
          width: 120,
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList('1004'),
          render: props => {
            return <span>{this.createDictText(props.row.isValid, '1004')}</span>;
          }
        },
      ];
    },
    addHandle() {
      this.handleType = 'add';
      this.showHandler();
    },
    editHandle(row) {
      this.handleType = 'edit';
      this.productId = row.productId;
      this.formData = row;
      this.showHandler();
    },
    detailHandle(row) {
      this.handleType = 'show';
      this.formData = row;
      console.log(row)
      this.showHandler();
    },
    showHandler() {
      this.dialogTitle = `车辆主数据信息`;
      this.visible = true;
    },
    changeHandle(val) {
        this.fetchParams = Object.assign({}, val);
    },
    collapseHandle() {
      this.$nextTick(() => {
        this.BaseTable.EXECUTE_RESET_HEIGHT();
      });
    },
    closeHandler(val, type) {
      this.visible = val;
      if (type === 'refresh') {
        // 重新加载
        this.fetchParams = { ...this.fetchParams };
      }
    },
    closeImportHandler(){
      this.visibleImport = false;
      // 重新加载
        this.fetchParams = { ...this.fetchParams };
    },
    closeAddCarsHandler(){
      this.visibleAddCars = false;
      // 重新加载
        this.fetchParams = { ...this.fetchParams };
    },
    async getDictBrandList() {
      const res = await getBrandList();
      if (res.resultCode === 200) {
        console.log(this.topFilterList,"this.topFilterList")
        this.topFilterList.find(item=>item.fieldName==='brandId').itemList = res.data.map(x => ({ value: x.brandId, text: x.brandName }));
        // this.topFilterList = [...this.topFilterList]
      }
    },
    async changeBrandSelect(brandsid) {
      // if (!brandsid) {
        this.topFilterList.find(item=>item.fieldName==='seriesId').initialValue = '';
        this.topFilterList.find(item=>item.fieldName==='seriesId').itemList = [];
        this.topFilterList.find(item=>item.fieldName==='modelId').initialValue = '';
        this.topFilterList.find(item=>item.fieldName==='modelId').itemList = [];
        this.topFilterList.find(item=>item.fieldName==='packageId').initialValue = '';
        this.topFilterList.find(item=>item.fieldName==='packageId').itemList = [];
      // } else {
      if (brandsid) {
        const res = await getSeriesList(brandsid);
        if (res.resultCode === 200) {
          this.topFilterList.find(item=>item.fieldName==='seriesId').itemList = res.data.map(x => ({ value: x.seriesId, text: x.seriesName }));
        }
      }
    },
    async changeSeriesSelect(seriessid) {
      const brandsid = this.topFilterList.find(item=>item.fieldName==='brandId').initialValue;
      /* if (!brandsid || !seriessid) {
        this.topFilterList.find(item=>item.fieldName==='modelId').initialValue = '';
        this.topFilterList.find(item=>item.fieldName==='modelId').itemList = [];
        this.topFilterList.find(item=>item.fieldName==='packageId').initialValue = '';
        this.topFilterList.find(item=>item.fieldName==='packageId').itemList = [];
      } else { */
      if (brandsid && seriessid) {
        this.topFilterList.find(item=>item.fieldName==='modelId').initialValue = '';
        this.topFilterList.find(item=>item.fieldName==='modelId').itemList = [];
        this.topFilterList.find(item=>item.fieldName==='packageId').initialValue = '';
        this.topFilterList.find(item=>item.fieldName==='packageId').itemList = [];
        const res = await getModelList(brandsid, seriessid);
        if (res.resultCode === 200) {
          this.topFilterList.find(item=>item.fieldName==='modelId').itemList = res.data.map(x => ({ value: x.modelId, text: x.modelName }));
        }
      }
      // }
    },
    async changeModelSelect(modelId) {
      const brandsid = this.topFilterList.find(item=>item.fieldName==='brandId').initialValue;
      const seriessid = this.topFilterList.find(item=>item.fieldName==='seriesId').initialValue;
      // if (!brandsid || !seriessid || !modelId) {
        this.topFilterList.find(item=>item.fieldName==='packageId').initialValue = '';
        this.topFilterList.find(item=>item.fieldName==='packageId').itemList = [];
      // } else {
      if (modelId) {

        const res = await getPackageList(brandsid, seriessid, modelId);
        if (res.resultCode === 200) {
          this.topFilterList.find(item=>item.fieldName==='packageId').itemList = res.data.map(x => ({ value: x.packageId, text: x.configName }));
        }
      }
      // }
    },
    async changePackageSelect(packageId) {
      const brandsid = this.topFilterList.find(item => item.fieldName === 'brandId').initialValue;
      const seriessid = this.topFilterList.find(item => item.fieldName === 'seriesId').initialValue;
      // if (!brandsid || !seriessid || !modelId) {
      this.topFilterList.find(item => item.fieldName === 'optionId').initialValue = '';
      this.topFilterList.find(item => item.fieldName === 'optionId').itemList = [];
      // } else {
      if (packageId) {
        const res = await getOptionListDictOEM(packageId);
        if (res.resultCode === 200) {
          this.topFilterList.find(item => item.fieldName === 'optionId').itemList = res.data.map(x => ({ value: x.optionId, text: x.optionName }));
        }
      }
      // }
    },
    async getColors() {
      const res = await getWcolorList();
      if (res.resultCode === 200) {
        this.topFilterList.find(item=>item.fieldName==='colorId').itemList = res.data.map(x => ({ value: x.colorId, text: x.colorName }));
      }
    },
    async getIColors() {
      const res = await getIcolorList();
      if (res.resultCode === 200) {
        this.topFilterList.find(item=>item.fieldName==='trimColorId').itemList = res.data.map(x => ({ value: x.colorId, text: x.colorName }));
      }
    },
    //导出
    requestExportData() {
      let params = JSON.parse(JSON.stringify(this.fetchParams));
      this.exportLoading = true;
      const option = {};
      getExcelListV3(params).then((response) => {
        exportExcelFile(response.data, '整车产品信息');
        this.exportLoading = false;
        // this.exportExcel(res.records)
      });
    },
    exportModelExcel() {
      const option = {
        tHeader: [
          '产品代码',
          '产品名称',
          '品牌',
          '车型',
          '车型',
          '配置',
          '数据来源',
          '车辆来源',
          '是否有效',
          '产品状态',
          '产品类别',
          '车场指导价',
          '销售指导价',
          '上市日期',
          '退市日期',
          '颜色',
          '内饰色',
          '备注'
        ],
        filterVal: [
          'productCode',
          'productName',
          'brandName',
          'seriesName',
          'modelName',
          'configName',
          'dataSources',
          'vehicleSources',
          'isValid',
          'productStatus',
          'productType',
          'oemDirectivePrice',
          'vehiclePrice',
          'enterDate',
          'exeuntDate',
          'color',
          'interiorColor',
          'remark'
        ],
        fileName: '车辆主数据信息模板'
      }
      exportFile(option, () => {
        this.exportLoading = false
      })
    },
    exportExcel(table) {
      const option = {
        tHeader: [
          '产品代码',
          '产品名称',
          '品牌',
          '车型',
          '车型',
          '配置',
          '数据来源',
          '车辆来源',
          '是否有效',
          '产品状态',
          '产品类别',
          '车场指导价',
          '销售指导价',
          '上市日期',
          '退市日期',
          '颜色',
          '内饰色',
          '备注'
        ],
        filterVal: [
          'productCode',
          'productName',
          'brandName',
          'seriesName',
          'modelName',
          'configName',
          'dataSources',
          'vehicleSources',
          'isValid',
          'productStatus',
          'productType',
          'oemDirectivePrice',
          'vehiclePrice',
          'enterDate',
          'exeuntDate',
          'color',
          'interiorColor',
          'remark'
        ],
        table: table,
        fileName: '车辆主数据信息' + parseTime(new Date())
      }
      exportFile(option, () => {
        this.exportLoading = false
      })
    },
  },
  created() {
    this.getDictBrandList()
    if (this.dataType !== '10461001') {
      this.getColors()
      this.getIColors()
    }
  },
  mounted() {
    this.BaseTable = this.$refs.table.$refs.pageTable;
  }
};
</script>

<style lang="less" scoped>
</style>
